/* Copyright 2024 Coremail
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { CMError, ErrorCode } from '../../../api';

/**
 * Exchange异常名称。
 */
export type ErrorName = 'EwsError' | 'HttpError' | 'BusinessError';

/**
 * Exchange异常。
 */
export interface ExchangeError<T = void> extends Error {
  name: ErrorName;
  code: number | string;
  data?: T;
}

/**
 * 业务异常错误码
 */
export  type BusinessError = 'XML_DECODED_ERROR' | 'XML_ENCODED_ERROR';

/**
 * Exchange异常转换为CMError。
 *
 * @param originError { ExchangeError } exchange异常。
 * @returns { CMError } CMError异常实例。
 */
export function exchangeErrorConvertToCMError(originError: ExchangeError): CMError {
  return new CMError(originError.message, ErrorCode.EXCHANGE_ERROR, originError)
}


